<?php

class Euso_Widget
{
	// Module where this widget defined
	protected $_ownerModule = null;
	protected $_active = null;
	protected $_idname = null;
	protected $_class = null;
	protected $_name = null;
	protected $_version = NULL;
	protected $_description = NULL;
	protected $_module = null;
	protected $_controller = null;
	protected $_action = null;
	protected $_title = NULL;
	protected $_parentName = NULL;
	protected $_params = array();


    public function __construct(array $options = null)
    {
        if (is_array($options)) {
            $this->setOptions($options);
        }
    }


    public function __set($name, $value)
    {
        $method = 'set' . ucfirst($name);
        $this->$method($value);
    }
    public function __get($name)
    {
        $method = 'get' . ucfirst($name);
        return $this->$method();
    }

    public function setOptions(array $options)
    {
        $methods = get_class_methods($this);
        foreach ($options as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods)) {
                $this->$method($value);
            }
        }
        return $this;
    }


	public function setOwner($ownerModule = null)
	{
		$this->_ownerModule = $ownerModule;
		return $this;
	}
	public function setActive($active = false)
	{
		$this->_active = $active;
		return $this;
	}
	public function setIdName($idname = null)
	{
		$this->_idname = $idname;
		return $this;
	}
	public function setClass($class = null)
	{
		$this->_class = $class;
		return $this;
	}
	public function setName($name = null)
	{
		$this->_name = $name;
		return $this;
	}
	public function setVersion($version = null)
	{
		$this->_version = $version;
		return $this;
	}
	public function setDescription($desc = null)
	{
		$this->_description = $desc;
		return $this;
	}
	public function setModule($module = null)
	{
		$this->_module = $module;
		return $this;
	}
	public function setController($controller = null)
	{
		$this->_controller = $controller;
		return $this;
	}
	public function setAction($action = null)
	{
		$this->_action = $action;
		return $this;
	}
	public function setTitle($title = NULL)
	{
		$this->_title = $title;
		return $this;
	}
	public function setParentName($widgetIdName = NULL)
	{
		$this->_parentName = $widgetIdName;
		return $this;
	}
	public function setParams($params = null)
	{
		if (is_array($params))
			$this->_params = $params;
		return $this;
	}


	public function getOwner()
	{
		return $this->_ownerModule;
	}
	public function getActive()
	{
		return $this->_active;
	}
	public function getIdName()
	{
		return $this->_idname;
	}
	public function getClass()
	{
		return $this->_class;
	}
	public function getName()
	{
		return $this->_name;
	}
	public function getVersion()
	{
		return $this->_version;
	}
	public function getDescription()
	{
		return $this->_description;
	}
	public function getModule()
	{
		if ($this->_module === NULL) {
			return 'default';
		}
		return $this->_module;
	}
	public function getController()
	{
		if ($this->_controller === NULL) {
			return 'index';
		}
		return $this->_controller;
	}
	public function getAction()
	{
		if ($this->_action === NULL) {
			return 'index';
		}
		return $this->_action;
	}
	public function getTitle()
	{
		if ($this->_title === NULL) {
			return $this->_name;
		}
		return $this->_title;
	}
	public function getParentName()
	{
		return $this->_parentName;
	}
	public function getParams()
	{
		return $this->_params;
	}
}